/*
 * Copyright (C) 2010 Seapeak.Xu
 *
 * fostmq may be copied only under the terms of the GNU General
 * Public License V3, which may be found in the fostmq source kit.
 *
 * Created on: 2010-7-30
 * Author: Seapeak.Xu
 */

#ifndef FOST_DATETIME_H
#define FOST_DATETIME_H
#ifdef __cplusplus
extern "C"
{
#endif

#include <time.h>
#include <ctype.h>
#include "fost_typedef.h"
/*
 * format the datetime to string without the internal operator
 * parameters:
 * 	datetime:the format datetime,but it maybe null
 * 	bufflen:the format buffer length,it contains the end-char 'null' or '\0'
 * 	buff:the format buffer
 * remarks:
 * 	when the datetime is null the datetime is now
 * 	the length equal or more than 15
 */
char *format_datetime(const struct tm *datetime, const size_t bufflen, char *buff);

/*
 * format the datetime to string with the internal operator
 * parameters:
 * 	datetime:the format datetime,but it maybe null
 * 	bufflen:the format buffer length,it contains the internal operatorand  the end-char 'null' or '\0'
 * 	buff:the format buffer
 * remarks:
 * 	when the datetime is null the datetime is now
 * 	the internal operator is '-' in yyyy-MM-day,and ':' in hh:mm:ss,the space between the days and hours
 * 	the length is equal or more then 20
 */
char *format_datetime_by_separator(const struct tm *datetime,
		const size_t bufflen, char *buff);

/*
 * get the datetime span
 * parameters:
 * 	result:the span from start datetime to end datetime
 * 	start:the start datetime
 * 	end:the end datetime
 * remarks:
 * 	the start and end must no-null
 */
int timeval_subtract(struct timeval *result,const struct timeval *start,
		const struct timeval *end);
/*
 * diff the time is out or not
 * parameters:
 * 	start: the start localtime,it must have value
 * 	end: the stop localtime,if it is NULL,it means datetime now
 * 	val:the time span seconds
 * result:
 * 	1:it is timeout
 * 	0:it is not timeout
 * 	-1: the start is null,the argument is error,the errno is EINVAL.
 *
 */
int istimeout(struct tm *start,struct tm *end,time_t val);
#ifdef __cplusplus
}
#endif
#endif /* FOST_DATETIME_H */
